package com.meitianhui.convenitenbuy.module.order.presenter;

import com.google.gson.Gson;
import com.meitianhui.convenitenbuy.App;
import com.meitianhui.convenitenbuy.base.BaseResponse;
import com.meitianhui.convenitenbuy.config.InfoProvider;
import com.meitianhui.convenitenbuy.http.ResponseObserver;
import com.meitianhui.convenitenbuy.module.order.contract.FightGroupOrderDetailContract;
import com.meitianhui.convenitenbuy.module.order.http.OrderApiDataSource;
import com.meitianhui.convenitenbuy.module.order.model.bean.FightGroupDetailPerson;
import com.meitianhui.convenitenbuy.module.order.model.bean.FightGroupOrderDetail;
import com.meitianhui.convenitenbuy.module.order.ui.activity.FightGroupOrderDetailActivity;

import java.util.HashMap;
import java.util.Map;

public class FightGroupOderDetailPresenter implements FightGroupOrderDetailContract.Presenter {

    private FightGroupOrderDetailActivity mContext;
    private final FightGroupOrderDetailContract.View view;

    public FightGroupOderDetailPresenter(FightGroupOrderDetailContract.View view,
                                         FightGroupOrderDetailActivity context) {
        this.view = view;
        this.mContext = context;
    }

    @Override
    public void getOrderDetail(String orderId) {
        Map<String, String> map = new HashMap<>();
        map.put("order_id", orderId);
        String paramsJson = new Gson().toJson(map);

        OrderApiDataSource.getInstance()
                .getFightGroupDetail(InfoProvider.getUserToken(App.getInstance()).getUser_token(),
                        "tsOrder.consumer.tsOrderDetailFind", paramsJson)
                .subscribe(new ResponseObserver<BaseResponse<FightGroupOrderDetail>>(App.getInstance()) {
                    @Override
                    public void onSuccess(BaseResponse<FightGroupOrderDetail> response) {
                        view.getOrderDetailSuccess(response.data);
                    }

                    @Override
                    public void onFail(int code, String msg) {
                        super.onFail(code, msg);
                        view.getOrderDetailFail(code, msg);
                    }
                });
    }

    @Override
    public void getOrderPerson(String activityId, String pageIndex, String pageSize) {
        Map<String, String> maps = new HashMap<>();
        maps.put("page_no", pageIndex + "");
        maps.put("page_size", pageSize + "");
        String pageJson = new Gson().toJson(maps);

        Map<String, String> map = new HashMap<>();
        map.put("activity_id", activityId);
        String paramsJson = new Gson().toJson(map);

        OrderApiDataSource.getInstance()
                .getFightGroupDetailPerson(InfoProvider.getUserToken(App.getInstance()).getUser_token(),
                        "tsActivity.consumer.joinListPageFind", pageJson, paramsJson)
                .subscribe(new ResponseObserver<BaseResponse<FightGroupDetailPerson>>(App.getInstance()) {
                    @Override
                    public void onSuccess(BaseResponse<FightGroupDetailPerson> response) {
                        view.getOrderPersonSuccess(response.data);
                    }
                });
    }

    @Override
    public void attachView(Object view) {
    }

    @Override
    public void detachView() {
    }

}
